<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: GetCircle.php
 * Date: 2017/1/2
 * Time: 23:13
 */

namespace app\api\model\page\msg;


use app\api\model\dao\DashangRecord;
use app\api\model\dao\MsgRecords;
use app\api\model\dao\MsgSet;
use app\api\model\dao\MsgUser;
use app\api\model\dao\NotePraise;
use app\api\model\dao\NoteReply;
use app\api\model\dao\UserAccount;
use app\library\Error;
use app\library\Flag;
use app\library\PageBase;
use think\Exception;
use think\Validate;

class GetMsgSet extends PageBase
{

    private $objMsgSet;

    public function __construct()
    {
        parent::__construct();

        $this->objMsgSet = new MsgSet();

    }

    /**
     * page 入口
     *
     * @param $param
     * @return array
     * @throws Exception
     */
    public function excute($param)
    {
        $ret = $this->checkToken($param);
        if (false === $ret) {
            throw new Exception('check token fail...', Error::ERR_NO_AUTH);
        }

        $ret = $this->objMsgSet->getByUserid($this->user_id);

        $this->data = [
            'open' => '0',
            'note_reply' => '0',
            'note_reply_reply' => '0',
            'not_faze' => '0',
            'not_faze_starttime' => '00:00',
            'not_faze_endtime' => '00:00',
        ];

        if (!empty($ret)) {
            unset($ret['id'], $ret['create_time'], $ret['user_id']);
            $this->data = $ret;
        } else {
            $this->objMsgSet->add(array_merge(['user_id' => $this->user_id], $this->data));
        }

        return $this->getRes();
    }

}
